#pragma
#include"nocopy.hpp"
#include"Log.hpp"
#include<cerrno>
#include<string.h>
#include"Socket.hpp"
#include<sys/epoll.h>



class Epoller:public nocopy
{
    static const int size=128;
public:
    Epoller()
    {
        _epfd=epoll_create(size);
        if(_epfd==-1)
        {
            lg(Error,"epoll_create error: %s",strerror(errno));
        }
        else{
            lg(Fatal,"epoll create success:%d ",_epfd);
        }
    }
    int EpolerWait(struct epoll_event revents[],int num)
    {
        int n=epoll_wait(_epfd,revents,num,timeout);
        return n;
    }
    int EpollUpdate(int oper,int sock,uint32_t event)
    { 
        int n=epoll_ctl(_epfd,oper,sock,nullptr);
        if(oper==EPOLL_CTL_DEL)
        {
           
            if(n!=0)
            {
                lg(Error,"epoller ctl delete error!");
            }
            else{
                struct epoll_event ev;
                ev.events=event;
                ev.data.fd=sock;
                n=epoll_ctl(_epfd,oper,sock,&ev);
                if(n!=0)
                {
                    lg(Error,"error");
                }

            }
            
        }
        return n;
    }
    ~Epoller()
    {}
private:
    int _epfd;
    int timeout{3000};
};